<template>
	<div class="Word">
		<input name="button" id="Button1" type="button" @click="SetKeyWord(true)" value="高亮显示关键字"/>
		<input name="button" id="Button2" type="button" @click="SetKeyWord(false)" value="取消关键字显示"/>
		<div style="height: 800px; width: auto" v-html="poHtmlCode" />
	</div>
</template>

<script>
	import axios from 'axios';
	  export default{
	    name: 'Word',
	    data(){
	      return {
	        poHtmlCode: '',
			id:'',
			key:''
	      }
	    },
	    created: function(){
			this.id=this.$route.query.id;
	      //由于vue中的axios拦截器给请求加token都得是ajax请求，所以这里必须是axios方式去请求后台打开文件的controller
	      axios.post("/api/SaveAndSearch/Word?id="+this.id).then((response) => {
	        this.poHtmlCode = response.data;
	      }).catch(function (err) {
	        console.log(err)
	      })
	    },
	    methods:{
			 OnPageOfficeCtrlInit() {
				pageofficectrl.AddCustomToolButton("保存", "Save", 1);
			 },
	         Save() {
	             pageofficectrl.WebSave();
	             //pageofficectrl.CustomSaveResult获取的是保存页面的返回值
	             if (pageofficectrl.CustomSaveResult == "ok")
	                 alert("保存成功");
	             else
	                 alert(pageofficectrl.CustomSaveResult);
	         },
	     
	         SetKeyWord(visible) {
	             if (this.key == "null" || "" == this.key) {
	                 alert("关键字为空。");
	                 return;
	             }
				 let falg = true;
				 pageofficectrl.word.HomeKey(6);
				 while(falg){		
					if(pageofficectrl.word.FindNextText(this.key)){
						if(visible){
							pageofficectrl.word.SetHighlightToSelection(7);
						}else{
							pageofficectrl.word.SetHighlightToSelection(0);
						}
					}else{
						pageofficectrl.word.HomeKey(6)
						break;
					}
				 }
				
				 
	         }
	    },
	    mounted: function(){
			this.key =  decodeURI(window.external.UserParams);
	      // 将vue中的方法赋值给window
			window.Save = this.Save;
			window.OnPageOfficeCtrlInit = this.OnPageOfficeCtrlInit;	
	    }
	}
</script>

